﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace CRM
{
    public partial class ServiceWorkLog : System.Web.UI.Page
    {
        protected override void OnPreLoad(EventArgs e)
        {
            Common.CheckMes.CheckState("User_ID", "Index.aspx", "用户登录信息丢失，青重新登录...");
            //取得权限信息
            string PowerMes = Common.EncryptString.DeMyEnncrypt(Common.GetMes.GetCookies("Power_Mes"), 6);
            if (PowerMes.IndexOf("2_1") < 0)
            {
                Common.MessageBox.Show(Page, "你没有查看的权限...", "Body.aspx", "BACK");
            }

            base.OnPreLoad(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadService();
                LoadData();
            }
        }

        /// <summary>
        /// 绑定用户信息
        /// </summary>
        private void LoadService()
        {
            //取得权限信息
            string PowerMes = Common.EncryptString.DeMyEnncrypt(Common.GetMes.GetCookies("Power_Mes"), 6);
            if (PowerMes.IndexOf("2_2") < 0)
            {
                ListItem LTUser = new ListItem(Common.EncryptString.DeMyEnncrypt(Common.GetMes.GetCookies("User_Name"), 6), Common.GetMes.GetSession("User_ID"));
                DDlService.Items.Clear();
                DDlService.Items.Add(LTUser);
            }
            else
            {
                DDlService.DataSource = BLL.ServiceUser.GetAllServiceUserInfo("");
                DDlService.DataTextField = "T_ServiceName";
                DDlService.DataValueField = "T_ServiceID";
                DDlService.DataBind();
            }
        }

        private void LoadData()
        {
            Model.DataTogther ModelTo = new CRM.Model.DataTogther();
            ModelTo.TableName = " V_GetServiceLog ";
            ModelTo.PageSize = PagerUserWork.PageSize;
            ModelTo.PageIndex = PagerUserWork.CurrentPageIndex;
            ModelTo.PrimaryKey = " T_SLogID ";
            ModelTo.SortType = 3;
            //排序中一定要包含主键 否则报错“无法找到表0”
            ModelTo.Order = " T_DateTime DESC,T_SLogID ASC ";
            ModelTo.FieldList = " * ";
            ModelTo.Where = GetWhere();
            ModelTo.RecorderCount = 0;

            int RecordCount = 0;
            RpUserService.DataSource = BLL.SysBase.GetDataList(ModelTo, out RecordCount);
            RpUserService.DataBind();
            PagerUserWork.RecordCount = RecordCount;
        }

        protected void PagerUserService_PageChanged(object sender, EventArgs e)
        {
            LoadData();
        }
        /// <summary>
        /// 获取查询条件
        /// </summary>
        private string GetWhere()
        {
            StringBuilder strWhere = new StringBuilder();
            strWhere.Append((DDlService.SelectedValue == "-1") ? "" : string.Format((string.IsNullOrEmpty(strWhere.ToString()) ? "" : " AND ") + " T_ServiceID='{0}' ", DDlService.SelectedValue.Trim()));
            return strWhere.ToString();
        }
    }
}
